import React, { useState, useEffect, useCallback } from 'react';
import {
    getSysDepartmentFindList,
    // getSofContractSelected 
} from '../../../../../../Api/listUrl';
import {
    ArtificialStatus
} from '../../../enum'
import { Form, Button, Select, Row, Col, message, DatePicker } from "antd";
import moment from 'moment';

const { Option } = Select;
const { RangePicker } = DatePicker;

/**
 * @description: 材料交易单 -- 出库 -- 搜索组件
 * @author: xiaoxujs
 * @updata: xiaoxujs（2021-09-18） 创建组件
 */

const SelectModule = ({ handleSelectModuleOk, handleSelectModuleReset }) => {
    const [form] = Form.useForm()
    const { resetFields } = form;
    const [departmentList, setDepartmentList] = useState([]); //部门list
    // const [contractList, setContractList] = useState([]); //合同list
    // const contractFun = useCallback(
    //     () => {
    //         ; (async () => {
    //             const { code, msg, data } = await getSofContractSelected();
    //             if (code === '20000') {
    //                 setContractList(data)
    //             } else {
    //                 message.error(msg);
    //             }
    //         })();
    //     },
    //     [],
    // )
    const departmentFun = useCallback(
        () => {
            ; (async () => {
                const { code, msg, data } = await getSysDepartmentFindList();
                if (code === '20000') {
                    setDepartmentList(data);
                } else {
                    message.error(msg);
                }
            })();
        },
        [],
    )
    useEffect(() => {
        departmentFun();
        // contractFun();
    }, [departmentFun])
    const handleReset = () => {
        resetFields()
        handleSelectModuleReset()
    }
    const onFinish = (values) => {
        if (values.time) {
            values.grantDateStart = moment(values.time[0]).format('YYYY-MM-DD');
            values.grantDateEnd = moment(values.time[1]).format('YYYY-MM-DD');
            delete values.time;
        }
        handleSelectModuleOk(values)
    };
    return <Form
        {...layout}
        name="basic"
        initialValues={{ remember: true }}
        onFinish={onFinish}
        form={form}
    >
        <Row>
            <Col span={6}>
                <Form.Item name="time" label="分摊时间" hasFeedback>
                    <RangePicker
                        // showTime={{ format: 'HH:mm:ss' }}
                        // format="YYYY-MM-DD HH:mm:ss"
                    />
                </Form.Item>
            </Col>
            {/* <Col span={6}>
                <Form.Item name="conNo" label="合同编号" hasFeedback>
                    <Select placeholder="请选择合同编号">
                        {
                            contractList.map(item => <Option value={item.name} key={item.id}> {item.name} </Option>)
                        }
                    </Select>
                </Form.Item>
            </Col> */}
            <Col span={6}>
                <Form.Item name="assumeDep" label="领用部门" hasFeedback>
                    <Select placeholder="请选择领用部门">
                        {
                            departmentList.map(item => <Option value={item.id} key={item.id}> {item.name} </Option>)
                        }
                    </Select>
                </Form.Item>
            </Col>
            <Col span={6}>
                <Form.Item name="artType" label="人工类别" hasFeedback>
                    <Select placeholder='请选择'>
                        {
                            ArtificialStatus.map((item, index) => <Option value={index} key={item + index}>{item}</Option>)
                        }
                    </Select>
                </Form.Item>
            </Col>
        </Row>
        <Row>
            <Col span={24} className="bottom_button_box">
                <Form.Item wrapperCol={{ offset: 0, span: 24 }}>
                    <Button
                        type="primary"
                        htmlType="submit"
                        style={{
                            height: '38px',
                            width: '78px',
                            borderRadius: '4px'
                        }}
                    >
                        搜索
                    </Button>
                    <Button
                        onClick={handleReset}
                        style={{
                            height: '38px',
                            width: '78px',
                            borderRadius: '4px'
                        }}
                    >重置</Button>
                </Form.Item>
            </Col>
        </Row>
    </Form>
}
const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 14 },
};
export default SelectModule;